<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateCreditEditionTable extends Migration
{
    /**
     * 创建积分排行版表
     *
     * @return void
     */
    public function up()
    {
        Schema::create('credit_edition', function (Blueprint $table) {
            //表属性
            $table->engine = 'InnoDB';
            $table->charset = 'utf8';
            $table->collation = 'utf8_general_ci';
            //表字段
            $table->increments('id');
            $table->integer('user_id')->comment('用户id');
            $table->integer('year')->comment('年份');
            $table->integer('month')->comment('月份');

            $table->integer('year_credit')->comment('年总积分');
            $table->integer('month_credit')->comment('月总积分');
            $table->integer('credit')->comment('个人总积分');

            $table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'))->comment('创建时间');
            $table->timestamp('updated_at')->nullable()->comment('更新时间');
            //创建索引
            $table->index('user_id');
            $table->index('year');
            $table->index('month');
            $table->unique(['user_id','year','month']);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('credit_edition');
    }
}
